package com.zm.product.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zm.product.dao.ProductDao;
import com.zm.product.model.Product;
import com.zm.product.service.IProductTCCService;
import com.zm.product.service.ProductService;
import io.seata.rm.tcc.api.BusinessActionContext;
import org.springframework.stereotype.Service;

@Service
public class ProductTCCService extends ServiceImpl<ProductDao, Product> implements IProductTCCService {
    @Override
    public Boolean reduceStock(Long id) {
        Boolean result=false;
        Product byId = this.getById(id);
        if (byId!=null&&byId.getNum()>0){
            byId.setNum(byId.getNum()-1);
            result=byId.updateById();
        }
        return result;
    }

    @Override
    public boolean confirm(BusinessActionContext ctx) {
        System.err.println("-----------confirm-------------");
        return true;
    }
    @Override
    public boolean cancel(BusinessActionContext ctx) {
        System.err.println("-----------cancel-------------");
        return true;
    }
}
